﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WhittleList.Bll;

namespace WhittleList.Tests.Mocks
{
    public class FakeSiteRepository : Moq.Mock<ISiteRepository>
    {
        public FakeSiteRepository()
        { }


        internal void SetSites(List<FakeSite> siteData)
        {
            var grouped = siteData.GroupBy(x => x.Object.OwnerId);
            foreach (var group in grouped)
            {
                this.Setup(x => x.Site_GetAllByOwnerId(group.Key)).Returns(group.Select(x => x.Object).AsQueryable());
            }
            foreach (var site in siteData)
            {
                this.Setup(x => x.Site_GetById(site.Object.Id)).Returns(site.Object);
                this.Setup(x => x.Site_GetByUrl(site.Object.Url)).Returns(site.Object);
            }
        }

        internal void SetProjects(List<FakeProject> projectData)
        {
            foreach (var group in projectData.GroupBy(x => x.Object.SiteId))
            {
                this.Setup(x => x.Project_GetAllBySiteId(group.Key)).Returns(group.Select(x => x.Object).AsQueryable());
            }
            foreach (var project in projectData)
            {
                this.Setup(x => x.Project_GetById(project.Object.Id)).Returns(project.Object);
            }
        }

        internal void SetSections(List<FakeSection> sectionData)
        {
            foreach (var group in sectionData.GroupBy(x => x.Object.ProjectId))
            {
                this.Setup(x => x.Section_GetAllByProjectId(group.Key)).Returns(group.Select(x => x.Object).AsQueryable());
            }
            foreach (var section in sectionData)
            {
                this.Setup(x => x.Section_GetById(section.Object.Id)).Returns(section.Object);
            }
        }

        internal void SetItems(List<FakeItem> itemData)
        {
            foreach (var item in itemData.GroupBy(x => x.Object.SectionId))
            {
                this.Setup(x => x.Item_GetByAllBySectionId(item.Key)).Returns(item.Select(x => x.Object).AsQueryable());
            }
            foreach (var item in itemData)
            {
                this.Setup(x => x.Item_GetById(item.Object.Id)).Returns(item.Object);
            }
        }
    }
}
